
.left-navi-section.payment-settings.has-stripe

  .row.paypal-wizard.no-border
    .col-12
      = render partial: 'general_prefs_form', locals: {payment_prefs_form: payment_prefs_form, payment_prefs_valid: payment_prefs_valid, currency: currency, available_currencies: available_currencies, support_email: support_email, payments_connected: stripe_connected || paypal_connected, country_name: country_name}

    .paypal-wizard-content.no-padding
      .row
        .col-12
          %h2
            = t("admin.payment_preferences.connect_a_payment_provider")
          - if !stripe_allowed && !paypal_allowed
            - support_link = link_to t("admin.payment_preferences.contact_support"), "mailto:#{support_email}"
            - help_link = link_to t("admin.payment_preferences.no_payments_link_text"), "#{knowledge_base_url}/currencies-supported-in-a-sharetribe-marketplace", target: "_blank"
            = t("admin.payment_preferences.you_cannot_use_online_payments", currency: @current_community.currency, country_name: country_name, support_link: support_link, help_link: help_link).html_safe
          - else
            - if stripe_allowed && paypal_allowed && stripe_enabled && paypal_enabled
              - popup_link = link_to t("admin.payment_preferences.which_to_choose"), '#', id: "choose_payment_popup_link"
              = t("admin.payment_preferences.you_can_use_stripe_or_paypal", choose_link: popup_link).html_safe
              - learn_more = link_to(t('layouts.branding.learn_more'), " #{knowledge_base_url}/how-to-delay-payments-and-hold-funds-with-stripe", target: "_blank")
              - help_text = t('admin.communities.settings.automatically_confirmed_no_escrow_stripe_info', learn_more: learn_more).html_safe
              = render partial: 'layouts/info_text', locals: { text: help_text }

              - help_text = t('admin.communities.settings.buyer_transaction_fees_are_only_supported_with_stripe')
              = render partial: 'layouts/info_text', locals: { text: help_text }

              = render layout: "layouts/lightbox", locals: { id: "payment_choose_popup_content"} do
                - text_with_line_breaks_html_safe do
                  = t("admin.payment_preferences.choose_popup_text")
                - help_url = "#{knowledge_base_url}/differences-between-stripe-and-paypal"
                = link_to t("admin.payment_preferences.read_more_about_paypal_and_stripe"), help_url,  target: "_blank"

              - content_for :extra_javascript do
                :javascript
                  $('#choose_payment_popup_link').click(function() { $('#payment_choose_popup_content').lightbox_me({centered: true, zIndex: 1000000}); });

            - elsif paypal_allowed && paypal_enabled
              - paypal_kb_link = link_to t("admin.payment_preferences.read_more_paypal"), "#{knowledge_base_url}/payment-with-paypal/guide-to-getting-started-with-paypal-payments", target: "_blank"
              = t("admin.payment_preferences.you_can_use_paypal_only", read_more_link: paypal_kb_link).html_safe
            - elsif stripe_allowed && stripe_enabled
              - stripe_kb_link = link_to t("admin.payment_preferences.read_more_stripe"), "#{knowledge_base_url}/differences-between-stripe-and-paypal", target: "_blank"
              = t("admin.payment_preferences.you_can_use_stripe_only", read_more_link: stripe_kb_link).html_safe
              - learn_more = link_to(t('layouts.branding.learn_more'), " #{knowledge_base_url}/how-to-delay-payments-and-hold-funds-with-stripei", target: "_blank")
              - help_text = t('admin.communities.settings.automatically_confirmed_no_escrow_stripe_info', learn_more: learn_more).html_safe
              = render partial: 'layouts/info_text', locals: { text: help_text }
            - else
              - support_link = link_to t("admin.payment_preferences.contact_support"), "mailto:#{support_email}"
              - help_link = link_to t("admin.payment_preferences.no_payments_link_text"), "#{knowledge_base_url}/supported-payments-currencies", target: "_blank"
              = t("admin.payment_preferences.you_cannot_use_online_payments", currency: @current_community.currency, country_name: country_name, support_link: support_link, help_link: help_link).html_safe

            .row.connect-row
              - if stripe_enabled && stripe_allowed
                - if stripe_connected
                  - if stripe_enabled_by_admin
                    .col-6
                      %h3.paypal-account-connected
                        =icon_tag("check", ["icon-fix"])
                        =t("admin.payment_preferences.stripe_connected.title")
                      = link_to "#", id: "config_stripe_toggle" do
                        = icon_tag("edit", ["icon-fix"])
                        = t("admin.payment_preferences.change_settings")
                      %br
                      = link_to disable_admin_payment_preference_path(payment_gateway: :stripe),
                        data: {confirm: t("admin.payment_preferences.confirm_disable", gateway: 'STRIPE')},
                        id: "disable_stripe" do
                        = icon_tag("cross", ["icon-fix"])
                        = t("admin.payment_preferences.stripe_connected.disable")
                  - else
                    .col-6
                      %h3.paypal-account-disabled
                        =icon_tag("cross", ["icon-fix"])
                        =t("admin.payment_preferences.stripe_connected.disabled")
                      = link_to enable_admin_payment_preference_path(payment_gateway: :stripe),
                        id: "enable_stripe" do
                        = icon_tag("unlock", ["icon-fix"])
                        = t("admin.payment_preferences.stripe_connected.enable")
                - else
                  .col-6
                    = link_to t("admin.payment_preferences.configure_stripe"), "#", class: "button", id: "config_stripe_toggle"

              - if paypal_enabled && paypal_allowed
                - if paypal_connected
                  - if paypal_enabled_by_admin
                    .col-6
                      %h3.paypal-account-connected
                        =icon_tag("check", ["icon-fix"])
                        =t("admin.payment_preferences.paypal_connected.title")
                      = link_to "#", id: "config_paypal_toggle" do
                        = icon_tag("edit", ["icon-fix"])
                        = t("admin.payment_preferences.change_settings")
                      %br
                      = link_to disable_admin_payment_preference_path(payment_gateway: :paypal),
                        data: {confirm: t("admin.payment_preferences.confirm_disable", gateway: 'PAYPAL')},
                        id: "disable_paypal" do
                        = icon_tag("cross", ["icon-fix"])
                        = t("admin.payment_preferences.paypal_connected.disable")
                  - else
                    .col-6
                      %h3.paypal-account-disabled
                        =icon_tag("cross", ["icon-fix"])
                        =t("admin.payment_preferences.paypal_connected.disabled")
                      = link_to enable_admin_payment_preference_path(payment_gateway: :paypal),
                        id: "enable_paypal" do
                        = icon_tag("unlock", ["icon-fix"])
                        = t("admin.payment_preferences.paypal_connected.enable")

                - else
                  .col-6{class: buyer_commission ? 'is-disabled' : ''}
                    = link_to t("admin.payment_preferences.configure_paypal"), "#", class: "button", id: "config_paypal_toggle"


    .payment-tabs.hidden.no-float
      .tabs-list
        - if stripe_enabled && stripe_allowed
          = link_to "Stripe", "#", data: {tab: 'stripe_tab'}, class: "tab-link stripe"
        - if paypal_enabled && paypal_allowed
          = link_to "PayPal", "#", data: {tab: 'paypal_tab'}, class: "tab-link paypal"

      - paypal_active = paypal_enabled && paypal_allowed && paypal_connected && paypal_enabled_by_admin
      - if stripe_enabled && stripe_allowed
        .tab-content.hidden#stripe_tab
          - if !stripe_connected
            - stripe_keys_link = "#{knowledge_base_url}/how-to-configure-your-stripe-account-and-get-api-keys-for-your-marketplace"
            = render partial: 'stripe_form', locals: {stripe_account: stripe_account, stripe_api_form: stripe_api_form, stripe_keys_link: stripe_keys_link}
          - else
            = render partial: 'stripe_connected', locals: {stripe_account: stripe_account}
            .paypal-wizard-divider
            = render partial: 'prefs_form', locals: {payment_prefs_form: stripe_prefs_form, currency: currency, available_currencies: available_currencies, support_email: support_email, pref_mode: 'stripe', knowledge_base_url: knowledge_base_url, paypal_active: paypal_active}

      - if paypal_enabled && paypal_allowed
        .tab-content.hidden#paypal_tab
          - if !paypal_connected
            = render partial: 'paypal_connect_account', locals: {order_permission_action: order_permission_action, buyer_commission: buyer_commission}
          - else
            = render partial: 'paypal_connected', locals: {paypal_account: paypal_account, order_permission_action: order_permission_action}
            .paypal-wizard-divider
            = render partial: 'prefs_form', locals: {payment_prefs_form: paypal_prefs_form, currency: currency, available_currencies: available_currencies, support_email: support_email, pref_mode: 'paypal', knowledge_base_url: knowledge_base_url, paypal_active: paypal_active}

    - if paypal_ready && stripe_ready
      = render partial: 'paypal_connect_own_notice', locals: {connected_mode: 'stripe_and_paypal'}
    - elsif stripe_ready
      = render partial: 'paypal_connect_own_notice', locals: {connected_mode: 'stripe_only'}
    - elsif paypal_ready
      = render partial: 'paypal_connect_own_notice', locals: {connected_mode: 'paypal_only'}

    = js_t(["admin.payment_preferences.fee_should_be_less_than_minimum_price",
      "admin.payment_preferences.the_transaction_fee_must_be_lower_than_100"])
    - content_for :extra_javascript do
      :javascript
        window.ST.initPaymentTabs()

    - if stripe_enabled && stripe_allowed && stripe_connected && stripe_enabled_by_admin && !stripe_ready
      - content_for :extra_javascript do
        :javascript
          $('#config_stripe_toggle').click();
    - elsif paypal_enabled && paypal_allowed && paypal_connected && paypal_enabled_by_admin && !paypal_ready
      - content_for :extra_javascript do
        :javascript
          $('#config_paypal_toggle').click();

